package transcode;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

public class GBKtoUTF {
	private static List<File> test(String fileDir) {  
        List<File> fileList = new ArrayList<File>();  
        File file = new File(fileDir);  
        File[] files = file.listFiles(new FileFilter() {
			@Override
			public boolean accept(File pathname) {
				return pathname.getName().endsWith(".java");
			}
		});// 获取目录下的所有文件或文件夹  
        if (files == null) {// 如果目录为空，直接退出  gsdfgsdg
            return null;  
        }  
        // 遍历，目录下的所有文件  
        for (File f : files) {  
            if (f.isFile()) {  
                fileList.add(f);  
            } else if (f.isDirectory()) {  
                System.out.println(f.getAbsolutePath());  
                test(f.getAbsolutePath());  
            }  
        }  
        return fileList;
    }  
  
   

	public static void main(String[] args) throws Exception{
		List<File> fileList = test("E:\\ws\\Shoot\\src\\com\\tarena\\fly");
		for (File f1 : fileList) {  
			File path = new File("E:\\ws\\Shoot\\src\\com\\tarena\\fly\\out");
	        System.out.println(f1.getName()); 
	        File f2 = new File(path,f1.getName());
			InputStreamReader isr = new InputStreamReader(
					new FileInputStream(f1), "gbk");
			OutputStreamWriter isw = new OutputStreamWriter(
					new FileOutputStream(f2), "utf-8");
			int len = 0;
			while ((len = isr.read()) != -1) {
				isw.write(len);
			}
			isw.close();
			isr.close();
		 }
	
	}

}
